<?php

/**
 * OwnerModel
 */
include_once 'Application/Views/owner/OwnerView.php';

class Application_Models_OwnerModel{
    private $_idOwner;
    private $_lastName;
    private $_name;
    private $_gender;
    private $_dateBirth;
    private $_address;
    
    function __construct() {
        
    }
    
    public function get_idOwner() {
        return $this->_idOwner;
    }

    public function set_idOwner($_idOwner) {
        $this->_idOwner = $_idOwner;
    }

    
    public function get_lastName() {
        return $this->_lastName;
    }

    public function set_lastName($_lastName) {
        $this->_lastName = $_lastName;
    }

    public function get_name() {
        return $this->_name;
    }

    public function set_name($_name) {
        $this->_name = $_name;
    }

    public function get_gender() {
        return $this->_gender;
    }

    public function set_gender($_gender) {
        $this->_gender = $_gender;
    }

    public function get_dateBirth() {
        return $this->_dateBirth;
    }

    public function set_dateBirth($_dateBirth) {
        $this->_dateBirth = $_dateBirth;
    }

    public function get_address() {
        return $this->_address;
    }

    public function set_address($_address) {
        $this->_address = $_address;
    }

    /**
     * registrar
     * 
     */
    
    public function insertOwner(){
        global $config;                  
        $objDb=new Class_Db();
        $objDb->selectManager()->connect();

        $columns="'"."$this->_idOwner"."','"."$this->_lastName"."','"."$this->_name".
                "','"."$this->_gender"."','"."$this->_dateBirth"."','"."$this->_address"."'";
        //die($columns);
        $table=$config['tableOwner'];
        $consult=$objDb->selectManager()->insertAdd(strtoupper($columns), $table);
        $viewPerson=new Application_Views_OwnerView();
        if($consult){            
            //$viewPerson->formListOwner("si se pudo");
            header("Location: principal.php?action=show&controller=Owner");
        }else{
            $viewPerson->formListOwner("no se pudo");
        }
        
    }
    public static function showOwner(){
        global $config;
        
        $objDb=new Class_Db();
        $objDb->selectManager()->connect();

        $table=$config['tableOwner'];
        $columns="*";
        $consult=$objDb->selectManager()->selectAdd($columns, $table);
        $viewPerson=new Application_Views_OwnerView();          
        $viewPerson->showOwner($consult);
    }
    /**
     * actualizar
     * 
    */ 
    public function updateOwner(){
        global $config;
        
        $objDb=new Class_Db();
        $objDb->selectManager()->connect();

        $table=$config['tableOwner'];
        $columns="'"."$this->_lastName"."','"."$this->_name".
                "','"."$this->_gender"."','"."$this->_dateBirth"."','"."$this->_address"."'";
        $condition="'$this->_idOwner'";
        
        $query="update $table set apellidos='".$this->_lastName."',nombres='".$this->_name."',
            sexo='".$this->_gender."',fecha_nacimiento='".$this->_dateBirth."',direccion='".$this->_address."' 
                where dni_propietario= $condition";
        //die($query);
        //$consult=$objDb->selectManager()->updateAdd($columns, $table, $condition);     
        $consult=$objDb->selectManager()->update(strtoupper($query));
        //die($consult);
        if($consult){
            //echo 'modificado con exito';
            header("Location: principal.php?action=show&controller=Owner");
        }else{
            echo 'algo anda mal';
        }
    }
    /**
     * listar
     * 
     
    public static function selectOwner(){
        
    }*/
}